#include "ControlGlobal.h"

static u32 gCheckBtConnectTimeId = 0;
static bool gIsBtConnect = false;

static void onKeyClickCallback(s32 key)
{
    if (VALUE_PROP_IS_OPEN_KEY_VOLUME)
    {
        sdkSysBeep(SDK_SYS_BEEP_OK);
    }
}

static void checkBtConnectStatus()
{
    bool isBtConnect = false;

    if (!isDeviceSupportBT())
    {
        return;
    }

    if (!sdkTimerIsEnd(gCheckBtConnectTimeId, 500))
    {
        return;
    }

    gCheckBtConnectTimeId = sdkTimerGetId();
    isBtConnect = sdkBtIsConnected();
    if (isBtConnect == gIsBtConnect)
    {
        return;
    }
    gIsBtConnect = isBtConnect;
    if (gIsBtConnect)
    {
        sdkSysBeep(SDK_SYS_BEEP_OK);
        sdkmSleep(500);
        sdkSysBeep(SDK_SYS_BEEP_OK);
    }
    else
    {
        sdkSysBeep(SDK_SYS_BEEP_OK);
        sdkmSleep(100);
        sdkSysBeep(SDK_SYS_BEEP_OK);
    }
}

void onControlLoopListener()
{
    checkBtConnectStatus();
}

void initControl()
{
    gCheckBtConnectTimeId = sdkTimerGetId();
    gIsBtConnect = false;

    initUpdateTimeControl();
    initMenuControl();
    sdkRegisterLoopListener(onControlLoopListener);
    sdkKeySetOnKeyClickCallback(onKeyClickCallback);
}

